﻿using System;

namespace PersonExercises
{
    class Person:IPropertyChangedNotification
    {
        private string firstName;
        private string lastName;
        private bool male;
        private DateTime birthDate;
        private long egn;

        public event PropertyChangedEventHandler PropertyChanged;

        public event EventHandler EGNChanged;

        public Person(string firstName, string lastName, bool male, DateTime birthDate)
        {
            this.firstName = firstName;
            this.lastName = lastName;
            this.male = male;
            this.birthDate = birthDate;
        }

        public string FirstName
        {
            get
            {
                return firstName;
            }
            set
            {
                if (value!=firstName)
                {
                    OnPropertyChange("FirstName",firstName,value);
                }
                firstName = value;
            }
        }

        public string LastName
        {
            get
            {
                return lastName;
            }
            set
            {
                if (value != lastName)
                {
                    OnPropertyChange("LastName", lastName, value);
                }
                lastName = value;
            }
        }

        public bool Male
        {
            get
            {
                return male;
            }
            set
            {
                if (value != male)
                {
                    OnPropertyChange("Male", male, value);
                }
                male = value;
            }
        }

        public DateTime BirthDate
        {
            get
            {
                return birthDate;
            }
            set
            {
                if (value != birthDate)
                {
                    OnPropertyChange("BirthDate", birthDate, value);
                }
                birthDate = value;
            }
        }

        public long Egn
        {
            get
            {
                return egn;
            }
            set
            {
                egn = value;
                OnEGNChange();
            }
        }

        protected void OnEGNChange()
        {
            if (EGNChanged!=null)
            {
                EGNChanged(this, new EventArgs());
            }
        }

        protected void OnPropertyChange(string propName,object oldValue,object newValue)
        {
            if (PropertyChanged!=null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propName,oldValue,newValue));
            }
        }
    }
}
